package com.hursing.tractor.view;

import android.graphics.Rect;

import com.hursing.tractor.baseview.UIView;
import com.hursing.tractor.model.GameData;

public final class UIDesktopPanelView extends UIView {
	
	@Override
	public UIView layout(int w, int h) {
		final int firstTop = 0;
		final int firstBottom = (int) (h * 0.16);
		final int secondTop = (int) (h * 0.18);
		final int secondBottom = (int) (h * 0.34);
		final int thirdTop = (int) (h * 0.36);
		final int thirdBottom = (int) (h * 0.52);
		mFrame = new Rect(0, firstTop, w, thirdBottom);
		
		sViews[VIEW_TOP_CARD].frame(new Rect((int) (w * 0.35), firstTop, (int) (w * 0.65), firstBottom));
		sViews[VIEW_BOTTOM_CARD].frame(new Rect((int) (w * 0.35), thirdTop, (int) (w * 0.65), thirdBottom));
		sViews[VIEW_LEFT_CARD].frame(new Rect((int) (w * 0.03), secondTop, (int) (w * 0.33), secondBottom));
		sViews[VIEW_RIGHT_CARD].frame(new Rect((int) (w * 0.67), secondTop, (int) (w * 0.97), secondBottom));
		sViews[VIEW_KITTY_CARD].frame(new Rect((int) (w * 0.35), secondTop, (int) (w * 0.65), secondBottom));
		return this;
	}
	
	@Override
	protected boolean doOnTouchDown(int x, int y) {
		for (int i = VIEW_BOTTOM_CARD; i <= VIEW_LEFT_CARD; i++) {
			if (sViews[i].frame().contains(x, y)) {
				GameData.instance().handPosition(i - VIEW_BOTTOM_CARD);
				return true;
			}
		}
		return false;
	}
}
